<?php

class CommentController extends Zend_Controller_Action
{
    public function indexAction ()
    {    
        
    }
    
    public function updateAction()
    {
        $commentService = Service_Comment::getInstance();
        $commentId = $this->_getParam('id',null);
        $form = new Form_Comment($commentService->findComment($commentId));
        if($this->getRequest()->isPost()){
            if($form->isValid($this->getRequest()->getPost())){
                $comment = new Model_Comment($this->getRequest()->getPost());
                $comment->id = $commentId;
                $comment = $commentService->saveComment($comment);
                $this->_redirect('/post/view/id/' . $comment->post_id);
            }
        }
        $this->view->form = $form;
    }
    
    public function deleteAction()
    {
        $commentService = Service_Comment::getInstance();
        $commentId = $this->_getParam('id', null);
        $comment = $commentService->findComment($commentId);
        $commentService->deleteComment($comment);
        $this->_redirect('/post/view/id/' . $comment->post_id);
    }   
}

